<?php


namespace App\Http\Repositories\ProductCenter;


use App\Http\Repositories\BaseRepository;
use App\Models\ProductCenter\Models\SizeModel;

class SizeRepository extends BaseRepository
{
    public $size;
    public function __construct(SizeModel $size)
    {
        $this->size = $size;
    }

    public function getSizeInfo($data)
    {
        $where['id'] = $data['id'];
        return $this->size->getInfo($where);
    }

    public function getSizeList($data)
    {
        $where = [];
        is_real_exists(@$data['label']) && $where['label'] = ['like', '%'.$data['label'].'%'];
        is_real_exists(@$data['value']) && $where['value'] = ['like', '%'.$data['value'].'%'];
        is_real_exists(@$data['status']) && $where['status'] = $data['status'];
        is_real_exists(@$data['system_id']) && $where['system_id'] = $data['system_id'];

        return $this->size->getSizeList($where, $data['operate']);

    }

    public function addSize($data)
    {
        $insert['code'] = $data['code'];
        $insert['system_id'] = $data['system_id'];
        $insert['label'] = $data['label'];
        $insert['create_user'] = $this->size->getCurrentUser();
        $insert['create_user_uuid'] = $this->size->getCurrentUserId();

        $value = explode(',', $data['value']);
        foreach ($value as $v) {
            $insert['value'] = $v;

            $this->size->create($insert);
        }

        return [];
    }

    public function editSize($data)
    {
        $where['id'] = $data['id'];

        $this->size->editItem($where, $data);

        return [];
    }

    public function delSize($data)
    {
        return $this->size->deleteItem($data);
    }
}
